#include "Comm.hpp"

int main()
{
    char buffer[1024];
    SetNonBlock(0); // 非阻塞
    while (1)
    {
        ssize_t s = read(0, buffer, sizeof(buffer) - 1);
        // 读到了
        if (s > 0)
        {
            buffer[s] = 0;
            cout << "收到: " << buffer << endl;
        }
        // 底层IO条件没就绪，和IO读取错误 都是返回值负数，怎么区分？
        // 错误码！
        else
        {
            if (errno == EWOULDBLOCK || errno == EAGAIN)
            {
                cout << "正在等待输入呢" << endl;
                sleep(1);
                continue;
            }
            cout << "读取错误, errno: " << errno << endl;
            sleep(1);
        }
    }
}